import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            inquiry_order: {
                // id: '',
                // patients_id_from_patient_id_name: '',
                // order_time: '',
                // order_code: '',
                // status: '',
                // coupon_discount: '',
                // totalprice: '',
            },
            menzhen_order: {
                // id: '',
                // patients_id_from_patient_id_name: '',
                // order_time: '',
                // order_code: '',
                // status: '',
                // coupon_discount: '',
                // totalprice: '',
                // totalpayable: '',
            },
            operation_order: {
                // id: '',
                // patients_id_from_patient_id_name: '',
                // order_time: '',
                // order_code: '',
                // status: '',
                // coupon_discount: '',
                // totalprice: '',
            },
        };
        return this.state;
    },
    getInquiryOrder() {
        var me = this;
        var data = {income_record_id: this.$router.params.id, order_type:this.$router.params.type};
        var flag = true;
        if(me.beforeGetInquiryOrder) {
            flag = me.beforeGetInquiryOrder(data);
        }
        if(flag) {
            app.post("web/wallet/orderRecordDetail", data, function(res) {
                me.setState({inquiry_order: res.data.result});
                if(me.afterGetInquiryOrder) {
                    me.afterGetInquiryOrder(res);
                }
            });
        }
    },
    getMenzhenOrder() {
        var me = this;
        var data = {id: me.state.menzhen_order.id};
        var flag = true;
        if(me.beforeGetMenzhenOrder) {
            flag = me.beforeGetMenzhenOrder(data);
        }
        if(flag) {
            app.get("api/menzhen_orders/get", data, function(res) {
                me.setState({menzhen_order: res.data.result});
                if(me.afterGetMenzhenOrder) {
                    me.afterGetMenzhenOrder(res);
                }
            });
        }
    },
    getOperationOrder() {
        var me = this;
        var data = {id: me.state.operation_order.id};
        var flag = true;
        if(me.beforeGetOperationOrder) {
            flag = me.beforeGetOperationOrder(data);
        }
        if(flag) {
            app.get("api/operation_orders/get", data, function(res) {
                me.setState({operation_order: res.data.result});
                if(me.afterGetOperationOrder) {
                    me.afterGetOperationOrder(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {
        this.getInquiryOrder()
    },
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
